跳到主要内容

RS-232 通信设置 Node-RED

RS-232 通信设置

本页介绍如何使用 Node-RED 和串口转换器在 OV80i 摄像头与外部设备之间建立 RS-232 通信。

通信概述

摄像头可以通过 Node-RED 和串口转换器,实现与其他设备的 RS232 通信。

系统要求:

  • RS485 转 RS232 串口转换器(需硬件采购)
  • Node-RED 配置
  • 带有 RS232 端口的外部设备

所需硬件

您需要采购一个 RS485 转 RS232 串口转换器。我们推荐使用 [DTECH DT-9017]。该设备用于将摄像头输出的 RS485 信号转换为 RS232 信号。

硬件规格:

  • 转换器类型: RS485 转 RS232 串口转换器
  • 推荐型号: DTECH DT-9017
  • 功能: 将摄像头的 RS485 信号转换为 RS232 格式
  • 来源: 需第三方采购

🔗 物理连接设置

步骤 1:将串口转换器连接到摄像头

按照下图所示,将串口转换器连接到摄像头。

步骤 2:建立与 RS232 端口的连接

将串口转换器的另一端连接到目标 RS232 端口,完成摄像头与 RS232 端口之间的物理连接。

连接链路:
OV80i 摄像头 → RS485 输出 → 串口转换器 → RS232 端口 → 外部设备

配置 Node-RED 逻辑

进入 IO Block 配置 Node-RED 逻辑。请按照 Node-RED 基础章节的步骤导入以下提供的 JSON 文件:

配置步骤:

  1. 访问摄像头界面的 IO Block
  2. 打开 Node-RED 配置
  3. 导入提供的 JSON 配置文件
  4. 部署更新后的流程

Node-RED 配置 JSON

复制并导入以下 JSON 配置以设置 RS-232 通信:

[
{
"id": "7cb1ab03670cd840",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "8aabc4c53d9cca67",
"type": "ui_group",
"name": "Home",
"tab": "51b1608995f5ea89",
"order": 1,
"disp": true,
"width": "27",
"collapse": false
},
{
"id": "51b1608995f5ea89",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
},
{
"id": "42dd086612a76167",
"type": "ui_base",
"theme": {
"name": "theme-light",
"lightTheme": {
"default": "#0094CE",
"baseColor": "#0094CE",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"edited": false
},
"darkTheme": {
"default": "#097479",
"baseColor": "#097479",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"edited": false
},
"customTheme": {
"name": "Untitled Theme 1",
"default": "#4B7930",
"baseColor": "#4B7930",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
},
"themeState": {
"base-color": {
"default": "#0094CE",
"value": "#0094CE",
"edited": false
},
"page-titlebar-backgroundColor": {
"value": "#0094CE",
"edited": false
},
"page-backgroundColor": {
"value": "#fafafa",
"edited": false
},
"page-sidebar-backgroundColor": {
"value": "#ffffff",
"edited": false
},
"group-textColor": {
"value": "#1bbfff",
"edited": false
},
"group-borderColor": {
"value": "#ffffff",
"edited": false
},
"group-backgroundColor": {
"value": "#ffffff",
"edited": false
},
"widget-textColor": {
"value": "#111111",
"edited": false
},
"widget-backgroundColor": {
"value": "#0094ce",
"edited": false
},
"widget-borderColor": {
"value": "#ffffff",
"edited": false
},
"base-font": {
"value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
}
},
"angularTheme": {
"primary": "indigo",
"accents": "blue",
"warn": "red",
"background": "grey",
"palette": "light"
}
},
"site": {
"name": "Node-RED Dashboard",
"hideToolbar": "false",
"allowSwipe": "false",
"lockMenu": "false",
"allowTempTheme": "true",
"dateFormat": "DD/MM/YYYY",
"sizes": {
"sx": 48,
"sy": 48,
"gx": 6,
"gy": 6,
"cx": 6,
"cy": 6,
"px": 0,
"py": 0
}
}
},
{
"id": "c47cc2d81c408a36",
"type": "serial-port",
"name": "",
"serialport": "/dev/ttyTHS1",
"serialbaud": "9600",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "",
"dtr": "high",
"rts": "low",
"cts": "high",
"dsr": "high",
"newline": "\\\\n",
"bin": "false",
"out": "char",
"addchar": "\\\\n",
"responsetimeout": "10000"
},
{
"id": "2baab5bd0cce1230",
"type": "debug",
"z": "7cb1ab03670cd840",
"name": "debug 1",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 580,
"y": 580,
"wires": []
},
{
"id": "4e7d748dce95e6c6",
"type": "change",
"z": "7cb1ab03670cd840",
"name": "set rts high",
"rules": [
{
"p": "payload",
"t": "set",
"pt": "msg",
"to": "{\\"rts\\": \\"high\\"}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 400,
"wires": [
[
"8e62d87d6be5a946"
]
]
},
{
"id": "e3b7598d774c2bd6",
"type": "delay",
"z": "7cb1ab03670cd840",
"name": "",
"pauseType": "delay",
"timeout": "20",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 630,
"y": 320,
"wires": [
[
"270a4fa8fb4a4978",
"5325a871a1f84955"
]
]
},
{
"id": "104dae3badcde04b",
"type": "change",
"z": "7cb1ab03670cd840",
"name": "set rts low",
"rules": [
{
"p": "payload",
"t": "set",
"pt": "msg",
"to": "{\\"rts\\": \\"low\\"}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 360,
"wires": [
[
"8e62d87d6be5a946"
]
]
},
{
"id": "651284218146186a",
"type": "inject",
"z": "7cb1ab03670cd840",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "GOOD",
"payloadType": "str",
"x": 250,
"y": 360,
"wires": [
[
"342f2ea893daee9b"
]
]
},
{
"id": "270a4fa8fb4a4978",
"type": "delay",
"z": "7cb1ab03670cd840",
"name": "",
"pauseType": "delay",
"timeout": "20",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 830,
"y": 360,
"wires": [
[
"104dae3badcde04b"
]
]
},
{
"id": "17d922879e91c8a7",
"type": "delay",
"z": "7cb1ab03670cd840",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "0.5",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 420,
"y": 580,
"wires": [
[
"2baab5bd0cce1230"
]
]
},
{
"id": "342f2ea893daee9b",
"type": "delay",
"z": "7cb1ab03670cd840",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "0.5",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 430,
"y": 320,
"wires": [
[
"e3b7598d774c2bd6",
"4e7d748dce95e6c6"
]
]
},
{
"id": "54165e10b820a5f5",
"type": "inject",
"z": "7cb1ab03670cd840",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "FAIL",
"payloadType": "str",
"x": 250,
"y": 300,
"wires": [
[
"342f2ea893daee9b"
]
]
},
{
"id": "2549782ab378b378",
"type": "serial in",
"z": "7cb1ab03670cd840",
"name": "",
"serial": "c47cc2d81c408a36",
"x": 260,
"y": 580,
"wires": [
[
"17d922879e91c8a7"
]
]
},
{
"id": "5325a871a1f84955",
"type": "serial out",
"z": "7cb1ab03670cd840",
"name": "",
"serial": "c47cc2d81c408a36",
"x": 820,
"y": 320,
"wires": []
},
{
"id": "8e62d87d6be5a946",
"type": "serial control",
"z": "7cb1ab03670cd840",
"name": "",
"serial": "c47cc2d81c408a36",
"x": 830,
"y": 400,
"wires": [
[]
]
},
{
"id": "263de9e9ed71a09e",
"type": "comment",
"z": "7cb1ab03670cd840",
"name": "Send any string here to pass it to the selected serial port. The rest of the nodes just manage information flow.",
"info": "",
"x": 550,
"y": 240,
"wires": []
},
{
"id": "15d30e67047b53fc",
"type": "comment",
"z": "7cb1ab03670cd840",
"name": "Recieve strings here.",
"info": "",
"x": 280,
"y": 520,
"wires": []
}
]
  • 端口: /dev/ttyTHS1
  • 波特率: 9600
  • 数据位: 8
  • 校验位:
  • 停止位: 1
  • 流控: 由流逻辑管理 RTS/CTS

建立通信

发送数据

使用 FAIL/GOOD 节点通过 RS232 端口将摄像头检测结果发送给接收设备。

数据传输:

  • 来源: 摄像头检测结果
  • 方式: FAIL/GOOD 节点输出
  • 目标: 通过 RS232 发送至外部设备
  • 内容: 合格/不合格状态及检测数据

接收数据

利用 debug 节点接收来自 RS232 端口的数据,并将其集成到系统逻辑中。

数据接收:

  • 来源: 通过 RS232 端口的外部设备
  • 方式: 使用 debug 节点监控
  • 集成: 融入 Node-RED 逻辑
  • 用途: 系统控制与反馈

✅ 设置完成

按照以上步骤,您已成功建立摄像头与 RS232 端口之间的通信。

验证清单:

  • ✅ 串口转换器正确连接至摄像头
  • ✅ RS232 端口连接完成
  • ✅ Node-RED 逻辑已配置并部署
  • ✅ 数据传输测试通过(摄像头至外部设备)
  • ✅ 数据接收验证通过(外部设备至摄像头)

🔗 参见

  • 操作指南:配置 IO Block 设置
  • 参考资料:Node-RED 基础
  • 操作指南:导入与导出 Node-RED 流程
  • 概念说明:数字 I/O 逻辑:NPN 与 PNP